/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.corpus;

import view.controller.corpus.ControllerKorpusPreview;
import javax.swing.JOptionPane;
import model.corpus.Corpus;

/**
 *
 * @author Djordje Gligorijevic
 */
public class FrmKorpusPreview extends javax.swing.JDialog {

    private ControllerKorpusPreview controllerKorpusPreview;

    /**
     * Creates new form FrmKorpusPreview
     */
    public FrmKorpusPreview(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmbBoxChooseKorpus = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblKorpusPreview = new javax.swing.JTable();
        btnRemoveSentence = new javax.swing.JButton();
        btnRemoveKorpus = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        cmbBoxChooseKorpus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbBoxChooseKorpusActionPerformed(evt);
            }
        });

        tblKorpusPreview.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tblKorpusPreview);

        btnRemoveSentence.setText("Remove sentence");
        btnRemoveSentence.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveSentenceActionPerformed(evt);
            }
        });

        btnRemoveKorpus.setText("Remove korpus");
        btnRemoveKorpus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveKorpusActionPerformed(evt);
            }
        });

        jLabel1.setText("choose korpus to preview:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cmbBoxChooseKorpus, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnRemoveSentence)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnRemoveKorpus, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbBoxChooseKorpus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRemoveSentence)
                    .addComponent(btnRemoveKorpus))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbBoxChooseKorpusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbBoxChooseKorpusActionPerformed
        controllerKorpusPreview.showSingleKorpus((Corpus) cmbBoxChooseKorpus.getSelectedItem());
    }//GEN-LAST:event_cmbBoxChooseKorpusActionPerformed

    private void btnRemoveKorpusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveKorpusActionPerformed
        try {
            int answer = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this corpus?", null, JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.YES_OPTION) {
                controllerKorpusPreview.removeKorpus((Corpus) cmbBoxChooseKorpus.getSelectedItem());
                JOptionPane.showMessageDialog(this, "Korpus has been successfully removed.");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnRemoveKorpusActionPerformed

    private void btnRemoveSentenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveSentenceActionPerformed
        try {
            int answer = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this sentence?", null, JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.YES_OPTION) {
//                controllerKorpusPreview.removeKorpus((Corpus) cmbBoxChooseKorpus.getSelectedItem());
                JOptionPane.showMessageDialog(this, "Sentence has been successfully removed.");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnRemoveSentenceActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmKorpusPreview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmKorpusPreview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmKorpusPreview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmKorpusPreview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrmKorpusPreview dialog = new FrmKorpusPreview(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnRemoveKorpus;
    private javax.swing.JButton btnRemoveSentence;
    private javax.swing.JComboBox cmbBoxChooseKorpus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblKorpusPreview;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the btnRemoveKorpus
     */
    public javax.swing.JButton getBtnRemoveKorpus() {
        return btnRemoveKorpus;
    }

    /**
     * @param btnRemoveKorpus the btnRemoveKorpus to set
     */
    public void setBtnRemoveKorpus(javax.swing.JButton btnRemoveKorpus) {
        this.btnRemoveKorpus = btnRemoveKorpus;
    }

    /**
     * @return the btnRemoveSentence
     */
    public javax.swing.JButton getBtnRemoveSentence() {
        return btnRemoveSentence;
    }

    /**
     * @param btnRemoveSentence the btnRemoveSentence to set
     */
    public void setBtnRemoveSentence(javax.swing.JButton btnRemoveSentence) {
        this.btnRemoveSentence = btnRemoveSentence;
    }

    /**
     * @return the cmbBoxChooseKorpus
     */
    public javax.swing.JComboBox getCmbBoxChooseKorpus() {
        return cmbBoxChooseKorpus;
    }

    /**
     * @param cmbBoxChooseKorpus the cmbBoxChooseKorpus to set
     */
    public void setCmbBoxChooseKorpus(javax.swing.JComboBox cmbBoxChooseKorpus) {
        this.cmbBoxChooseKorpus = cmbBoxChooseKorpus;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jScrollPane1
     */
    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    public void setjScrollPane1(javax.swing.JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    /**
     * @return the trbKorpusPreview
     */
    public javax.swing.JTable getTrbKorpusPreview() {
        return tblKorpusPreview;
    }

    /**
     * @param trbKorpusPreview the trbKorpusPreview to set
     */
    public void setTrbKorpusPreview(javax.swing.JTable trbKorpusPreview) {
        this.tblKorpusPreview = trbKorpusPreview;
    }

    /**
     * @return the controllerKorpusPreview
     */
    public ControllerKorpusPreview getControllerKorpusPreview() {
        return controllerKorpusPreview;
    }

    /**
     * @param controllerKorpusPreview the controllerKorpusPreview to set
     */
    public void setControllerKorpusPreview(ControllerKorpusPreview controllerKorpusPreview) {
        this.controllerKorpusPreview = controllerKorpusPreview;
    }

    public void updateForm() {
        controllerKorpusPreview.getKorpusesComboBox();
        tblKorpusPreview.setComponentPopupMenu(controllerKorpusPreview.postaviPopupmenu());
    }
}
